<?php
/* 
* @Author: LDF QQ 47121862
* @Date:   2014-05-15 11:35:30
* @Last Modified by:   LDF QQ 47121862
* @Last Modified time: 2014-06-04 10:17:54
*/
/*栏目控制器*/
class CategoryControl extends AuthControl{
	private $cateModel;
	public function __auto(){
		$this->cateModel=K('Categroy');
	}
	//栏目列表
	public function index(){
		$cate=cache('categoryCache');
		$cate = Data::tree($cate,'cname');
		$this->category=$cate;
		$this->display();
	}
	//添加栏目
	public function add(){
		if(IS_POST){
			if($this->cateModel->addCate()){
				$this->success('添加栏目成功...');
			}else{
				$this->error($this->cateModel->error);
			}
		}else{
			//查询所有商品类型并分配
			$this->goodsType = cache('goodsType');
			$this->display();
		}
	}
	//修改栏目
	public function edit(){
		if(IS_POST){
			if($this->cateModel->editCate()){
				$this->success('修改栏目成功',U('index'));
			}else{
				$this->error($this->cateModel->error);
			}
		}else{
			$cid = Q('cid',0,'intval');
			$cate=cache('categoryCache');
			$category = Data::tree($cate,'cname');
			foreach ($category as $k => $v) {
				//禁用自身及其子栏目及封面
				if($v['cid']==$cid || $v['cate_type']==1 || Data::isChild($category,$v['cid'],$cid)){
					$category[$k]['disabled'] = 'disabled = ""';
				}
				//选取父级
				if($category[$cid]['pid']==$v['cid']){
					$category[$k]['selected'] = 'selected = ""';
				}
			}
			$this->category = $category;
			$this->field = $cate[$cid];
			$this->display();
		}
	}
	// 删除栏目
	public function del(){
		if($this->cateModel->delCate()){
			$this->success('删除栏目成功..');
		}else{
			$this->error($this->cateModel->error);
		}
	}
	//更新栏目缓存
	public function updateCache(){
		if($this->cateModel->updateCache()){
			$this->success('更新缓存成功');
		}
	}
}
